<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态添加数据</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <label for="">序号：</label>
        <input type="text" v-model="tmpId" placeholder="请输入序号">
        <p>序号 is : {{ tmpId }}</p>

        <label for="">姓名：</label>
        <input type="text" v-model="tmpName" placeholder="请输入姓名">
        <p>姓名 is : {{ tmpName }}</p>

        <button @click="add">添加</button>
        <ul id="example-1">
            <li v-for="item in list" :key="item.id">
                序号：{{ item.id }}---姓名：{{ item.name }}
            </li>
        </ul>
    </div>

    <script type="text/javascript">
        new Vue({
            el: '#app',
            data: {
                tmpId: '',
                tmpName: '',
                list: [
                    { id: 1, name: '张三' },
                    { id: 2, name: '李四' },
                    { id: 3, name: '王五' },
                    { id: 4, name: '赵四' }
                ]
            },
            methods: {
                add() {
                    //数据添加元素
                    this.list.push({
                        id: this.tmpId,
                        name: this.tmpName 
                    })
                }
            }
        })
    </script>
</body>
</html>